﻿using MVCOA.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVCOA.Areas.Manage.Controllers
{
    public class HotNavController : Controller
    {
        //
        // GET: /Manage/HotNav/
   
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult GetParentdata()
        {
            //var sexData = [{ parentName: 1, text: '男' }, { parentName: 0, text: '女' }];
            IBLL.ICate_SecondBLL second = OperateContext.Current.BLLSession.ICate_SecondBLL;
            List<MODEL.Cate_Second> list = second.GetListBy(q => true).Select(s => s.ToPOCO()).ToList();
            List<Parentstr> list2 = new List<Parentstr>();
            foreach (MODEL.Cate_Second s in list)
            {
                Parentstr p = new Parentstr() { parentName = s.id, text = s.name };
                list2.Add(p);
            }
            IBLL.ICate_ThirdBLL third = OperateContext.Current.BLLSession.ICate_ThirdBLL;
            List<MODEL.Cate_Third> list3 = third.GetListBy(q => true).Select(s => s.ToPOCO()).ToList();
            foreach (MODEL.Cate_Third s1 in list3)
            {
                Parentstr p = new Parentstr() { parentName = s1.id, text = s1.name };
                list2.Add(p);
            }
            return Json(list2);
        }
        public ActionResult Getdata()
        {
            IBLL.IHotNavBLL first = OperateContext.Current.BLLSession.IHotNavBLL;
            List<MODEL.HotNav> list = first.GetListBy(q => true).Select(s => s.ToPOCO()).ToList();
            var gridData = new
            {
                Rows = list,
                Total = 1
            };
            return Json(gridData);
        }
        [HttpPost]
        public void Setdata(FormCollection fc)
        {
            // IBLL.ICate_FisrtBLL first = OperateContext.Current.BLLSession.ICate_FisrtBLL;
            string names = fc["name"];
            int ids = Convert.ToInt32(fc["id"]);
            if (ids == 0)
            {
                if (OperateContext.Current.BLLSession.IHotNavBLL.GetListBy(s => s.name == names).ToList().Count() == 0)
                {

                    MODEL.HotNav s = new MODEL.HotNav() { name = names };
                    OperateContext.Current.BLLSession.IHotNavBLL.Add(s);

                }


            }
            else
            {

                MODEL.HotNav s = new MODEL.HotNav() { id = ids, name = names };
                OperateContext.Current.BLLSession.IHotNavBLL.Modify(s, "name");


            }
        }
        [HttpPost]
        public void Deldata(FormCollection fc)
        {
            int ids = Convert.ToInt32(fc["id"]);
            //OperateContext.Current.BLLSession.ICate_ThirdBLL.DelBy(s => s.firstId == ids);
            //OperateContext.Current.BLLSession.ICate_SecondBLL.DelBy(s => s.firstId == ids);
            OperateContext.Current.BLLSession.IHotNavBLL.DelBy(s => s.id == ids);
        }
    }
}
